<?php

/**
 * 
 * 
 * 
 CREATE  TABLE IF NOT EXISTS `bayes_filter_data` (
  `bayes_filter_data_id` INT NOT NULL AUTO_INCREMENT ,
  `filter_name` VARCHAR(80) NULL ,
  `filter_tables_db_name` VARCHAR(80) NULL ,
  `bayes_category_data_table_name` VARCHAR(80) NULL ,
  `bayes_feature_data_table_name` VARCHAR(80) NULL ,
  `bayes_map_data_table_name` VARCHAR(80) NULL ,
  `total_feature_count` INT NULL ,
  `total_message_count` INT NULL ,
  `total_category_count` INT NULL ,
  PRIMARY KEY (`bayes_filter_data_id`) ,
  UNIQUE INDEX `filter_name_UNIQUE` (`filter_name` ASC) )
ENGINE = InnoDB;
 * 
 */
class Bayes_filter_data_Model extends BayesDataTemplate
{
	
	protected $primary_key				= 'bayes_filter_data_id';

	protected $primary_val				= 'filter_name';
	
	/**
	 * Instanciate new Bayes_filter_data_Model object
	 * 
	 * @param string $filter_name
	 * @param string $db_name
	 * @param string $table_name
	 * 
	 * @return Bayes_filter_data_Model 
	 */
	public static function factory($filter_name,  $db_name = NULL, $table_name = NULL )
	{
		return BayesDataTemplate::factory('Bayes_filter_data_Model',array($table_name, $db_name, array('filter_name'=>$filter_name)));
	}
	
	
	/**
	 * This is only called once, when you want to create a new filter, 
	 * or update where it should find the other probability tables
	 * 
	 * @param string $db_name
	 * @param string $category_table_name
	 * @param string $feature_table_name
	 * @param string $map_table_name
	 * 
	 * @param bool $create
	 * 
	 * @return bool 
	 */
	function set_filter_database_and_table_names($db_name, $category_table_name, $feature_table_name, $map_table_name, $create = TRUE)
	{
		if(!$this->exists())
		{
			if($create)
			{
				$this->create();
			}
			else
			{
				return FALSE;
			}
		}
		
		$this->filter_tables_db_name = $db_name;
		$this->bayes_feature_data_table_name = $feature_table_name;
		$this->bayes_map_data_table_name = $map_table_name;
		$this->bayes_category_data_table_name = $category_table_name;
		$this->save();
		
		return TRUE;
	}
	
	
	
	
}